import sys,math
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Combo(QComboBox):
    def __init__(self,title,parent=None):
        super(Combo,self).__init__(parent)
        self.setAcceptDrops(True)
    def dragEnterEvent(self,e):
        print(e)
        if e.mimeData().hasText():
            e.accept()
        else:
            e.ignore()
    def dropEvent(self,e ):
        self.addItem(e.mimeData().text())


class Example(QWidget):
    def __init__(self):
        super(Example,self).__init__()
        self.initUi()
    def initUi(self):
        lo=QFormLayout()
        lo.addRow(QLabel("请把左边的文本拖拽到右边的下拉菜单"))
        edit=QLineEdit()
        edit.setDragEnabled(True)
        com=Combo("button",self)
        lo.addRow(edit,com)
        self.setLayout(lo)
        self.setWindowTitle('拖拽案例')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Example()
    demo.show()
    sys.exit(app.exec_())
